package com.nhn.ssi.dao;

import java.sql.SQLException;
import java.util.List;
import java.util.Map;

import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import com.nhn.ssi.bean.Order;
import com.nhn.ssi.bean.Product;
import com.nhn.ssi.bean.UserBean;
import com.nhn.ssi.util.Pager;

public class TestDaoImpl extends SqlMapClientDaoSupport implements TestDao {
	private static final String NAMESPACE = "user.";

	@SuppressWarnings("unchecked")
	public List findAllUserList() throws SQLException {
		return (List)getSqlMapClientTemplate().queryForList(NAMESPACE + "getAllUserList");
	}

	@SuppressWarnings("unchecked")
	public List findUserList(Pager pager) throws SQLException {
		return (List)getSqlMapClientTemplate().queryForList(NAMESPACE + "getUserList", pager);
	}

	public int getUserListSize() throws SQLException {
		return (Integer)getSqlMapClientTemplate().queryForObject(NAMESPACE + "getUserListSize");
	}

	public UserBean findUserById(String id) throws SQLException {
		return (UserBean)getSqlMapClientTemplate().queryForObject(NAMESPACE + "getUserById", id);
	}

	public void addUser(UserBean userBean) throws SQLException {
		this.getSqlMapClientTemplate().insert(NAMESPACE + "addUser", userBean);
	}

	public void saveCollection() throws SQLException {
		this.getSqlMapClientTemplate().insert(NAMESPACE + "addCollection");
	}

	public void deleteUser(String data) throws SQLException {
		getSqlMapClientTemplate().delete(NAMESPACE + "deleteUser", data);
	}

	public void modifyUser(UserBean userBean) throws SQLException {
		getSqlMapClientTemplate().update(NAMESPACE + "updateUser", userBean);
	}

	public UserBean login(String username, String password) throws SQLException {
		java.util.Map<String, String> map = new java.util.HashMap<String, String>();
		map.put("username", username);
		map.put("password", password);
		return (UserBean)getSqlMapClientTemplate().queryForObject(NAMESPACE + "findUser", map);
	}

	@SuppressWarnings("unchecked")
	public List<Product> selectProductList(Map<String, Object> map) throws SQLException {
		return (List<Product>)getSqlMapClientTemplate().queryForList("com.market.product." + "getProductList", map);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Order> getOrderList(Map<String, Object> map) throws SQLException {
		return (List<Order>)getSqlMapClientTemplate().queryForList("com.fanli.order." + "getOrderList", map);
	}

}
